using System;
using System.Linq;
using JNPF.Utils;
using System.Threading.Tasks;
using JNPF.Data;
using JNPF.Data.Util;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using JNPF.Basics.Models;

namespace JNPF.Basics.Logic
{
    public class jiushiJsconfigService: DataFactory, jiushiJsconfigIService
    {
		/// <summary>
		/// 获取信息
		/// </summary>
		/// <param name="id">主键id</param>
		/// <returns></returns>
		public async Task<JsconfigEntity> GetInfo(string id)
		{
			using (var db = this.Basic)
			{
				return await db.GetEntityAsync<JsconfigEntity>(m => m.Id == id);
			}
		}

		/// <summary>
		/// 列表（分页）
		/// </summary>
		/// <param name="input">请求参数</param>
		/// <returns></returns>
		public async Task<PageResult<JsconfigEntity>> GetPageList(jiushiJsconfigListQueryInput input)
		{
			using (var db = this.Basic)
			{
				var queryWhere = ExtLinq.True<JsconfigEntity>();
				var queryParam = input.queryJson.ToObject();
				//查询最小月份
				if (input.min.ToInt()!=0)
				{
					queryWhere = queryWhere.And(m => m.Min == input.min);
				}
				//查询最大月份
				if (input.max.ToInt()!=0)
				{
					queryWhere = queryWhere.And(m => m.Max == input.max);
				}
				//查询提成
				if (input.commission.ToDecimal()>0)
				{
				queryWhere = queryWhere.And(m => m.Commission == input.commission);
				}
				//查询描述
				if (!string.IsNullOrEmpty(input.description))
				{
					queryWhere = queryWhere.And(m => m.Description.Contains(input.description));
				}
				return await db.GetIQueryable<JsconfigEntity>().Where(queryWhere).GetPageResultAsync(input);
			}
		}

		/// <summary>
		/// 创建信息
		/// </summary>
		/// <param name="entity">实体对象</param>
		/// <returns></returns>
		public async Task<int> Create(JsconfigEntity entity)
		{
			using (var db = this.Basic)
			{
				return await db.InsertAsync(entity);
			}
		}

		/// <summary>
		/// 更新信息
		/// </summary>
		/// <param name="entity">实体对象</param>
		/// <returns></returns>
		public async Task<int> Update(JsconfigEntity entity)
		{
			using (var db = this.Basic)
			{
				return await db.UpdateAsync(entity);
			}
		}

		/// <summary>
		/// 删除信息
		/// </summary>
		/// <param name="entity">实体对象</param>
		/// <returns></returns>
		public async Task<int> Delete(JsconfigEntity entity)
		{
			using (var db = this.Basic)
			{
				return await db.DeleteAsync(entity);
			}
		}

		/// <summary>
		/// 列表
		/// </summary>
		/// <param name="input">请求参数</param>
		/// <returns></returns>
		public async Task<List<JsconfigEntity>> GetList(jiushiJsconfigListQueryInput input)
		{
			using (var db = this.Basic)
			{
				var queryWhere = ExtLinq.True<JsconfigEntity>();
				//查询最小月份
				if (input.min.ToInt()!=0)
				{
					queryWhere = queryWhere.And(m => m.Min == input.min);
				}
				//查询最大月份
				if (input.max.ToInt()!=0)
				{
					queryWhere = queryWhere.And(m => m.Max == input.max);
				}
				//查询提成
				if (input.commission.ToDecimal()>0)
				{
				queryWhere = queryWhere.And(m => m.Commission == input.commission);
				}
				//查询描述
				if (!string.IsNullOrEmpty(input.description))
				{
					queryWhere = queryWhere.And(m => m.Description.Contains(input.description));
				}
				return await db.GetIQueryable<JsconfigEntity>().Where(queryWhere).ToListAsync();
			}
		}


    }
}